package peterka.ecka;

import java.util.Vector;
import peterka.ecka.model.EItem;

/**
 *
 * @author mpeterka
 */
public class Finder {

    public static Vector find(Vector data, String search) {
        Vector vector = new Vector();
        String searchLower = search.toLowerCase();
        if (data != null) {
            for (int i = 0; i < data.size(); i++) {
                EItem elem = (EItem) data.elementAt(i);
                if (search != null
                        && (contains(elem.getCode().toLowerCase(), searchLower)
                        || contains(elem.getName().toLowerCase(), searchLower))) {
                    vector.addElement(elem);
                }
            }
        }
        Logger.debug("Found: " + vector.size() + " items.");
        return vector;
    }

    protected static boolean contains(String input, String searchTerm) {
        if (input != null && input.indexOf(searchTerm) > 0) {
            return true;
        }
        return false;
    }
}
